这是我的PHP代码
<?php
try
{
$mysqlConnection = mysqli_connect('localhost', 'root', 'root');
if($mysqlConnection)
{
echo "Connected"."\n";
mysqli_select_db('test',$mysqlConnection);
$result = mysqli_query("SELECT * from tbl_details");
$row = mysqli_fetch_array($result);
echo strlen($row);
}
else
{
echo "Not connected";
}
}
catch(Exception $exp)
{
echo $exp;
}
?>
我已经验证了凭据,并且表中还有数据,但我仍然没有记录。 任何指出为什么??
的更新:: 的
工作代码
<?php
try
{
$mysqlConnection = mysqli_connect('localhost', 'root', 'root','test');
if($mysqlConnection)
{
echo "Connected"."\n";
$result = $mysqlConnection->query("SELECT NAME,State FROM tbl_details");
echo $result->num_rows."\n";
}
else
{
echo "Not connected";
}
}
catch(Exception $exp)
{
echo $exp;
}
?>
答案 0 :(得分:4)
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
$resultaat = $mysqli->query("SELECT * FROM tabel");
while ($record = $resultaat->fetch_assoc())
{
print_r($record);
}
答案 1 :(得分:0)
您缺少这段代码来显示结果:
while($row = mysql_fetch_array($result))
{
echo $row['name of column'] . " " . $row['name of column'];
echo "<br />";
}
答案 2 :(得分:0)
尝试以下代码:
$link = mysql_connect('localhost','root','');
$db_selected = mysql_select_db('test',$link);
$result = mysql_query("SELECT * from tbl_details");
while($row = mysql_fetch_array($result))
{
echo $row['fieldname'];
};
答案 3 :(得分:0)
这是初学者的最佳网站 - 'MySQLi' for Beginners
并且记住不要使用mysql_函数,因为它们已被弃用。
一些示例代码
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}