开发者

mysqli and mysql insert into database commands

开发者 https://www.devze.com 2023-01-16 15:28 出处:网络
Can anybody give开发者_如何学JAVA me a basic full php-mysql insert into block of code for mysqli() and mysql_connect(). Many thanksThe PHP manual has excellent example blocks for almost every command.

Can anybody give开发者_如何学JAVA me a basic full php-mysql insert into block of code for mysqli() and mysql_connect(). Many thanks


The PHP manual has excellent example blocks for almost every command.

  • mySQL: mysql_query

  • mySQLi: mysqli_connect


Have a look at:

  • PHP/MySQL Tutorial

The mysqli version function usually have an i suffixed after mysql keyword. More on mysqli functions.


For connecting and selecting a database (selecting is optional):

$con = mysql_connect($username, $password);
$db = mysql_select_db($dbname);

Querying:

$result = mysql_query("SELECT id,name FROM table");
if(!$result) {
  echo mysql_error();
}
while($row = mysql_fetch_assoc($result)) {
   echo "Row data: " . $row['id'] . " - " . $row['name'];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消