ช่วยทีครับ ติดต่อฐานข้อมูลไม่ได้
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ช่วยทีครับ ติดต่อฐานข้อมูลไม่ได้
ช่วยทีครับ ติดต่อฐานข้อมูลไม่ได้
Copy
<?php
require_once 'config.php';
$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());
mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());
mysql_query("SET NAMES UTF8");
function dbQuery($sql)
{
$result = mysql_query($sql) or die(mysql_error());
return $result;
}
function dbAffectedRows()
{
global $dbConn;
return mysql_affected_rows($dbConn);
}
function dbFetchArray($result, $resultType = MYSQL_NUM) {
return mysql_fetch_array($result, $resultType);
}
function dbFetchAssoc($result)
{
return mysql_fetch_assoc($result);
}
function dbFetchRow($result)
{
return mysql_fetch_row($result);
}
function dbFreeResult($result)
{
return mysql_free_result($result);
}
function dbNumRows($result)
{
return mysql_num_rows($result);
}
function dbSelect($dbName)
{
return mysql_select_db($dbName);
}
function dbInsertId()
{
return mysql_insert_id();
}
?>
<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL ^ E_DEPRECATED);
// start the session
session_start();
// database connection config
$dbHost = 'localhost';
$dbUser = 'admin';
$dbPass = 'admin1234';
$dbName = 'itbookonline';
// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);
define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);
define('SECRET_KEY', 'itbookonline');
// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR', 'images/product/');
define('POWER_BY','<p>Power by PainCart and edit Thai version by <a href="http://www.swift-tutor.com">swift-tutor.com</a></p>');
// some size limitation for the category
// and product images
// all category image width must not
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 125);
// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH', true);
// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);
// the width for product thumbnail
define('THUMBNAIL_WIDTH', 125);
/* เอาออก ไม่เช่นนั้นอัพเดทตะกร้าไม่ได้
if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = trim(addslashes($value));
}
}
if (isset($_GET)) {
foreach ($_GET as $key => $value) {
$_GET[$key] = trim(addslashes($value));
}
}
} เอาออก
*/
// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';
// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>
<?php
$db_Host="localhost";
$db_Username="admin";
$db_Pass="admin1234";
$db_Name="itbookonline";
mysql_connect("$db_Host","$db_Username","$db_Pass") or die("could not connect to mysql");
mysql_select_db("$db_Name") or die ("no database");
mysql_query("SET NAMES uft8");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<? php
$products = array();
$sql = "SELECT * FROM tbl_product ORDER BY pd_name";
$result = mysql_query($sql) or die ('can not get product name');
while ($row = mysql_fetch_array($result)){
$products [] = $row['pd_name'];
}
?>
<pre>
<?php
var_dump($products);
?>
</pre>
</body>
</html>
![]()
ช่วยทีครับ มือใหม่ งงมาก
ช่วยทีครับ มือใหม่ งงมาก
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ