AdmiralQ Posted September 23 Share Posted September 23 Okay, let’s start with I know nothing about setting up a MySQL dB. I have used them for years but with a friend having helped me set up my last one literally more than a decade ago. I’ve purchased a new VPS and need the authentication script which I’ve used on my other site to function. Here is the old site’s script: <? $link = mysql_connect("localhost","xxxxxxxx","yyyyyyyy") or die("Could not connect: ".mysql_error()); mysql_select_db("zzzzzzzz")or die("Could not select database: ".mysql_error()); date_default_timezone_set('America/Winnipeg'); ?> x is the username, y is the password, and z is the dB name. This open dB link script works perfectly on my old site. Here is the script for the new site: $link = mysql_connect("localhost","xxxxxxxx","yyyyyyyy") or die("Could not connect: ".mysql_error()); mysql_select_db("zzzzzzzz")or die("Could not select database: ".mysql_error()); date_default_timezone_set('America/Winnipeg'); print "Test Alpha<br>"; As you can see they are practically identical. I’ve got the Test Alpha part in there just to help me verify page load, but the result on Chrome is a page which tells me: This page isn’t working. Emberedutech.com is currently unable to handle this request. HTTP ERROR 500. Other test pages to verify correct nameserver setting work, for example emberedutech.com/test_session1.php. I seem to be at the last step of setting up this website, but I am inexperienced (to say the least) with setting up dB’s. Please help. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 23 Share Posted September 23 Your main problem is that mysql_*** functions have been deprecated for years and now no longer exist (unless you are using a really ancient version of PHP, in which case you should upgrade) You need to use mysqli or PDO (PDO is definitely recommended). Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 23 Share Posted September 23 did you read the replies in your previous thread? they went into great detail what changes you will need to make to the database specific code and to your code in general. you should be updating and testing your code on a localhost development system, xampp or similar. constantly uploading files to a remote server to see the result of each change is huge waste of time. to get php to help you, by reporting and display all the errors it detects, you need to set php's error_reporting to E_ALL (it should always be this value) and set display_errors to ON. these settings should be in the php.ini on your development system. when you put these settings into your code, they won't do anything for a fatal parse/syntax errors because your code never runs in this case to cause the settings to take effect. when you move your tested code to the live server, you would have display_errors set to OFF, and log_errors set to ON, so that all php detected errors will get logged. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 23 Share Posted September 23 also, name the database connection variable as to the type of connection/extension you are using, e.g. $pdo, so that you can see or search through your code to find which database specific code has or has not been updated. Quote Link to comment Share on other sites More sharing options...
AdmiralQ Posted September 23 Author Share Posted September 23 Okay, I changed the mysql statements to mysqli and received the same message, and yes my old site has been running with PHP 5 for more than a decade, and I’m starting a new server obviously requiring current syntax. So could somebody provide me with current syntax for establishing an open connection? And also, I remember my friend (who set up my last dB for me) having to make some settings changes to make sure that the dB was accessible from everywhere. I tried to read up on this and found that I needed to add an access host as % to allow my students to login and access the dB from anywhere. This is not what I do for a living. I am a Spanish teacher and I use my admittedly limited knowledge to complement my classroom resources. I’m not a mechanic who doesn’t know how the car runs. I’m a teacher who doesn’t know how it runs, so please forgive the lack of knowledge and experience. I’m afraid I don’t know what $pdo is either. Previously it was just a simple process of opening a link to the dB and then sending queries when needed. If that remains the same then I suppose that’s what I need mostly, however, my question about are there any modifications to a dB once it’s first activated that need to be done besides creating the necessary user data. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 23 Share Posted September 23 (edited) 1 hour ago, AdmiralQ said: the dB was accessible from everywhere. it's your php code that accesses the database, not the students that use your web site. your students login via the php authentication script that runs on your web site. if you set the php error related settings to the values that i posted, instead of getting a http 500 error page, you will get the actual php errors, assuming that php is setup and works on the server. have you created a .php page with a phpinfo(); statement to confirm that php works at all? because the mysql_ extension has been removed, along with magic_quotes, that provided some protection against sql special characters being able to break the sql query syntax for string values, which is how sql injection is accomplished, ALL of the code dealing with data values being put directly into the sql query statements MUST be updated. if you are not interested or capable of doing this level of changes, you are going to need to hire someone. the PDO extension provides the simplest way of accomplishing these changes. Edited September 23 by mac_gyver Quote Link to comment Share on other sites More sharing options...
AdmiralQ Posted September 24 Author Share Posted September 24 (edited) 11 hours ago, mac_gyver said: to get php to help you, by reporting and display all the errors it detects, you need to set php's error_reporting to E_ALL (it should always be this value) and set display_errors to ON. these settings should be in the php.ini on your development system. I checked the .ini file and both of these settings were set already as default so the http 500 error page seems to be displayed despite those settings. And yes, I created a php page to verify PHP functionality and put the phpinfo() in it to get the configuration display. Your statement that "ALL of the code dealing with data values being put directly into the sql query statements MUST be updated" is very helpful to me as it helps me fundamentally understand I'm just going to have to approach dB queries from different angle. So I guess I have some PDO syntax to learn. I do not mean to sound ungrateful. I've just spent the last 12 years writing code for a massive website which I use to manage and prepare resources for my students, and which they use to access those resources and learn. This website is over 1,000 files large with many files containing several hundred lines of code and some over 1,000 ... so you can see why I've been reluctant to update my PHP and MySQL systems. Doing so is relegating ALL of my code, my tools, and my resources to the ash heap of history. This 2008 Mercedes Benz I've been using (metaphor for my old server and site) has proven to be a POWERFUL tool in my class, but it seems to upgrade to the new 2024 Mercedes Benz is going to take a lot of learning, patience and most of all time. So, as I said up above, I guess I have some PDO syntax to learn. Edited September 24 by AdmiralQ Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted September 24 Solution Share Posted September 24 (edited) in the phpinfo output, there's a value near the top named - Loaded Configuration File. is this the same php.ini that you checked? next, search for the error_reporting and display_errors output. what are both the local and master values for these? here's typical PDO connection code - $DB_HOST = ''; // database host name or ip address $DB_USER = ''; // database username $DB_PASS = ''; // database password $DB_NAME = ''; // database name $DB_ENCODING = 'utf8mb4'; // db character encoding. set to match your database table's character set. note: utf8 is an alias of utf8mb3/utf8mb4 $options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // set the error mode to exceptions. this is the default setting now in php8+ PDO::ATTR_EMULATE_PREPARES => false, // run real prepared queries PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // set default fetch mode to assoc ]; $pdo = new pdo("mysql:host=$DB_HOST;dbname=$DB_NAME;charset=$DB_ENCODING",$DB_USER,$DB_PASS,$options); in your previous thread, i have instructions on converting a query, that has php variables being put directly into it, into a prepared query. also from that thread - if you want to post examples of your existing code, i/we can show what it would look like using current practices. a lot of the coding suggestions given in that thread actually eliminate code, so that you can just remove things, rather than spending time updating them. Edited September 24 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Barand Posted September 24 Share Posted September 24 6 hours ago, AdmiralQ said: the http 500 error page seems to be displayed despite those settings. In your php.ini file, ensure "display_startup_errors" is also set to On Quote Link to comment Share on other sites More sharing options...
AdmiralQ Posted September 24 Author Share Posted September 24 (edited) Yes, so I understand the error (for whatever reason being HTTP 500) was the result of using antiquated syntax, and that I’m also going to have to re-learn how to interface with a dB using a new syntax. The PDO method mentioned early on got me watching some videos on that which very closely mimic the PDO connection code here. I’ve got quite a bit more PDO videos and research to do in order to rebuild the site, but thank all of you for your patience and input. Edited September 24 by AdmiralQ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.