-3

単純な挿入クエリが機能しない理由を理解するのに助けが必要です。

以下のコード:

<?php

// db info
define ( 'DB_HOST', '' );`enter code here`
define ( 'DB_USER', '' );
define ( 'DB_PASSWORD', '' );
define ( 'DB_NAME', '' );

create_db_connection ();
function create_db_connection() {
    global $con;

    $con = mysql_connect ( DB_HOST, DB_USER, DB_PASSWORD ) or die ( "connection not established" );
    $db = mysql_select_db ( DB_NAME, $con ) or die ( "database not connected" );
}


$sql= "insert into 'tbl_BonAproval' (OrderId,RestId) values (20001,98765)";


if (mysqli_query ( $db, $sql )) {
    echo "Successfully inserted " . mysqli_affected_rows ( $db ) . " row";
} else {
    echo "Error occurred: " . mysqli_error ( $db );
}
function close_mysql_connection() {
    global $con;
    mysql_close ( $con );
}

$result = mysql_query ( "SELECT * FROM `tbl_BonAproval`" );
$row = mysql_fetch_array ( $result );
print_r ( $row ); // print array
echo $row ['table field name']; // print field data

// $sql=mysql_query('INSERT INTO tbl_BonAproval (OrderId, RestId) VALUES (24553, 01001);');
                               // echo $sql;



mysql_close ( $conn );
class CallBack {
}

?>
4

3 に答える 3

5

その前身であるMySQLの代わりにMySQLiを試す必要があります。これがあなたの単純化されたコードです:

<?php

$conn=mysqli_connect("YourHost","YourUsername","YourPassword","YourDatabase");

if(mysqli_connect_errno()){

echo "Error".mysqli_connect_error();
}

mysqli_query($conn,"INSERT INTO tbl_BonAproval (OrderId, RestId) VALUES ('20001','98765')");

$result = mysqli_query ($conn, "SELECT * FROM tbl_BonAproval");
while($row = mysqli_fetch_array ($result)){
echo $row['table field name']; /* print field data */ 
}

?>
于 2014-03-25T09:13:16.207 に答える