Need Assistance Out of Date PHP Code

No. PDO is a php extension that provides a set of statements to use for accessing a database. Please see the php.net documentation - https://www.php.net/manual/en/book.pdo.php

The MySql database server itself is still the same. The basic sql query syntax remains the same, though converting to a prepared query requires removing variables from the sql statement, replacing them with ? place-holders, then supplying the removed variables as an array to an ->execute([…]) statement.

so pardon my lack of knowledge, but changing from mysql to mysli, do I just add the “i” to all the commands that have mysql, or are the newer commands that replace… i am afraid i am lost here.

The migration sections in the php.net documentation list the major, backward incompatible, changes you would need to consider - https://www.php.net/manual/en/appendices.php

Nope. There are calling parameter differences and some mysql statements don’t have equivalent mysqli statements. You will need to use the php.net documentation to find the proper use.

As was already stated, since you have to go through a learning exercise, you might as well skip the limited mysqli extension, and just learn how to use the PDO extension. Several of the active forum members would be more then willing to post PDO examples based on what you are currently doing in your code.

Ok I have actually made a “little progress” BUT, as I suspected, there are more errors/ warnings. While some of the page has actually loaded, it is not loading anything in the actual data base.

  1. Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\ComputerSuperStore\header2.php on line 34

  2. Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\ComputerSuperStore\index.php on line 23

  3. Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\ComputerSuperStore\index.php on line 23

  4. Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\ComputerSuperStore\index.php on line 30

They are the warnings, I have the code open in Visual Studio at the moment.

Well, in most cases, you need to add the connection to all your SELECT’s, FETCHES and QUERIES.
So, things like mysqli_select_db() would require the connection info first parameter. Query(), too… etc…
You create a connection and assign it to let’s say, $con… Then, mysqli_query($con, rest of line)
Basically, make the first parm a pointer back to the connection string. Make sense?

For beginners, the link I posted gives you all the examples for all of your function calls.

Yes I have been reading through the link you provided
And the use of $con is there in just about every case. Line 34 and line 35 from header2.php:

mysqli_select_db(“computersuperstore” ,$con);
require (‘topbar.php’);

Which is the first “warning”…

I note that mine reads (“computersuperstore” , $con), should it read ($con, “computersuperstore”) now?

$con is the FIRST parrm, before computersuperstore…

yep I changed that and now the warning has gone, no more warnings for header2.php.

index lines 22 to 34 which includes the remaining errors so far

<?php // Queries All Products where they are Featured or on Special $result = mysqli_query("SELECT * FROM products WHERE SpecFeat = 'YES' ") or trigger_error (mysqli_error()); //echo 'Displaying Results
'; //print_r(mysql_fetch_assoc($result)); //echo '
Results Displayed'; //exit; while ($row=mysqli_fetch_assoc($result)) { require ('tablelogincheck.php'); } ?>

AGAIN… The query(), fetch_assoc() and ALL mysqli functions need to be pointed to the $con as the first parm. Minor change but, the “improved” version of mysql (the i stands for improved), needs to point to the connection in each use.

NOTE: This improvement lets you use two databases at the same time in your application.
You just create two connections and use the correct one for whatever is needed…

So, I have adjusted the code now there is an error (not mine)

Warning : require_once(HTML/Common.php): failed to open stream: No such file or directory in C:\xampp\php\pear\Table.php on line 68

Fatal error : require_once(): Failed opening required ‘HTML/Common.php’ (include_path=‘C:\xampp\php\PEAR’) in C:\xampp\php\pear\Table.php on line 68

It is in a file not associated with my site, I did not create it)

It obviously points to a file/ folder and file that is not included in the XAMPP package

I am in the pear site but it is not allowing me to download the package(s) and there is no folder HTML Folder the require is pointing to:

require_once ‘HTML/Common.php’;
require_once ‘HTML/Table/Storage.php’;

I can see the "files in the Pear Site but not able to get them

Okay, this one depends on your layout of your system. It looks like you have stored your files in an odd place. Normally, you use the c:\xampp\htdocs\yoursitename to store your website in. You would create a name for the top or root folder that matches your website name. So, if this is for a Super-Store website, you might name the folder superstore. So, then all your files would be saved in the standard htdocs and under that file. So, c:\xampp\htdocs\superstore, which would be a folder you would create and place all of your websties files in it. If you have sub-folders such as “inc” or “includes” for included sub-files, those sub-folders go under or inside the superstore folder.

Now, if you have older code and it contains something you did not right, you can add // to the beginning of the line to comment it out. If it was for school back in 2012, it might be something that your code used and needs. PEAR is an extension of PHP and is used for many reasons.

So, my guess is that you need to use that pear file for displaying data in a table format. I have seen this somewhere a long time ago. So, you need to point your system to include the PEAR as an included PHP file. The command is something like this: include_path = “c\xampp\php\PEAR”;
But, first you need to see if PEAR is under the c\xampp\php\ Folder and if so, add the include_path.
If not, search your xampp folder and find where PEAR is and adjust the include_path to point at it. And, this line would be needed near or at the top of your file that needs the Table.php file… ( Before the include for it! )

I feel like you almost have this done already! Good for you! I am leaving in an hour, but, will check back in on you when I get home tonight. So, pat yourself on the back, Keith!

Yeah and all thanks to you which I appreciate very much. I just did a check on my files index.php and header2.php and cannot find even the word PEAR, pear, Pear anywhere in the code. and it is 0252 in the morning here, so I may have to pull the pin very shortly…

No, not in a file. You need to go into the files under c:\xampp\php and look for a FOLDER named pear.
Once you find that, you can add the include_path line at the top of any files that look for the Table.php file.
Where are you, if you do not mind? I am in VT, in the US and it is 1PM Saturday afternoon here.
Talk to you once you get back up!

I am in Queensland Australia, just gone 3am Sunday Morning here

Oh, nice ! I have helped several people from your area! I would love to visit there one day!
Well, get some sleep! I will check in on your later…

Ok, and thanks again so much for your help, guidance and assistance I really do appreciate it.

No problem! That is why we are on this site!

Sponsor our Newsletter | Privacy Policy | Terms of Service