Search This Blog

Thursday, July 11, 2019

MRP MySQL v PDO

XAMPP on my laptop is now running PHP V7.3.3
The old procedural API commands have been removed from PHP.  The jargon word is depricated.
My MRP system is full of the procedural calls.

QUESTION 1 - PDO or MySQLi
Reading a few web sites
https://websitebeaver.com/php-pdo-vs-mysqli
https://www.w3schools.com/php/php_mysql_connect.asp
"Both are object-oriented, but MySQLi also offers a procedural API."
So I will use MySQLi

CHANGES


OLD NEW  note the i's
. .
. .
mysql_fetch_array($result, MYSQL_ASSOC); $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
. .
mysql_query($query) $dB = $GLOBALS['db'];
mysqli_query($dB , $query)
. .
. .
. .
. .


$result = @mysql_pconnect("localhost", "user", "pass");
$result = mysqli_connect($host, $username, $password);

// https://stackoverflow.com/questions/22834458/deprecated-mysql-pconnect
// UPDATE: As pconnects have nearly no benefit,
// you should replace mysql_pconnect with mysql_connect in your scripts anyway.
if (!function_exists("mysql_pconnect"))
{
    function mysql_pconnect($host, $username, $password)
        {
        //return mysqli_connect("p:".$host, $username, $password);
        return mysqli_connect($host, $username, $password);
        }
}.


mysql_select_db ( string $database_name [, resource $link_identifier = NULL ] ) : bool

@mysql_select_db("db name")
mysqli_select_db ( $result , $dbname ) 

So it looks like the old way, the "link" was optional


Selects the default database to be used when performing queries against the database connection.
https://www.php.net/manual/en/mysqli.select-db.php
mysqli_select_db ( mysqli $link , string $dbname ) : bool
The link is the identifier returned by mysqli_connect
so I need
mysqli_select_db ( $result , $dbname

mysql_query()


mysql_query ( string $query [, resource $link_identifier = NULL ] ) : mixed
mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] ) : mixed

mysql_num_fields()
mysqli_num_fields($result)

mysql_fetch_array($result, MYSQL_ASSOC);
Note: MYSQL_ASSOC does not exist in PHP7
mysqli_fetch_assoc ( mysqli_result $result ) : array


mysql_insert_id
mysqli_insert_id ( mysqli $link ) : mixed
$urn = mysqli_insert_id($dB);






No comments:

Post a Comment