


Write a program in PHP to connect to the database and output all records of the table
PHP writing program can connect to the database and output all the records in the table to set the data
mysql_connect('localhost','root','') or die("Connection error"); //Link database
mysql_select_db('database') or die("Fail to select database.");//Select database
$sql="select * from `mytable`";
$result=mysql_query($sql);
echo '
".$rw." | ";
?>
How does native php output the last executed sql of mysql
method one:
$link = mysql_connect("192.168.1.1", "myuser", "mypass"); --Connect to the database
if(FALSE == $link)
{
echo "Connect database failed!";
}
$query =
"select * from a order by id";
mysql_select_db('test', $link);--Select database
$result = mysql_query($query);--Execute query statement
if(FALSE == $result)
{
echo "Querry failed!";
}
$i = 0;
$j = 0;
while($i {
$meta_c=0;
if($meta_c=mysql_fetch_row($result))--Get the result set of each row
{
while($j {
echo $meta_c[$j;
}
echo "
";
} // while;
$j=0;
}
mysql_free_result($result);--Release the result set
mysql_close($link);--Close the connection
?>
Method Two:
$link = mysql_connect("192.168.1.1", "myuser", "mypass"); --Connect to the database
if(FALSE == $link)
{
echo "Connect database failed!
";
}
mysql_select_db('test', $link);--Select database
$result = mysql_query("select * from a order by id");--Execute the query statement
if(FALSE == $result)
{
echo "Querry failed!";
}
while($row = mysql_fetch_array($result, MYSQL_NUM))--Get the value in the array, because the result set is stored in a two-dimensional array
{
foreach ($row as $col_value)--take values one by one
{
echo " $col_value ";
}
}
mysql_free_result($result);--Release the result set
mysql_close($link);)--Close the connection
?>
The above is the detailed content of Write a program in PHP to connect to the database and output all records of the table. For more information, please follow other related articles on the PHP Chinese website!

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

Do you run into Word text disappearing while typing? Some letters or even paragraphs might disappear from your document. What’s wrong with it? In this post from php.cn Website, we will take a closer look at the Word automatically deleting text issue

When you are trying to log into Overwatch 2, you may receive the LC-208 error message and it prevents your game from connecting to the game servers. This post from php.cn introduces how to fix the LC-208 Overwatch error.

Generally, you can quickly access and edit Google Drive files from File Explorer. However, sometimes you may encounter the issue of “Google Drive disappeared from File Explorer”. Here this post on php.cn tells you how to get Google Drive to show up i

Why is my computer on the welcome screen for so long? How to fix Windows 7 welcome screen slow? If you still run Windows 7 on your PC and meet this issue, you are in the right place and multiple solutions will be given here by php.cn.

Want to use the built-in password management tool – Credential Manager to manage your login credentials for web and apps? How can you open Credential Manager in Windows 11? In this post, php.cn collected multiple ways to access this utility, and let’

Microsft Defender Antivirus has a feature called Periodic scanning, which can be enabled when you have installed another antivirus product on a Windows 11/10 device. Now, this post from php.cn teaches you how to enable/disable Periodic scanning on Wi

Have you ever encountered the issue of “Excel hyperlinks not working”? Do you know how to deal with it? In this post from php.cn, you can get several feasible solutions to get rid of this problem. And you will know a professional data recovery tool t


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft