View Full Version : Check MySQL version

07-26-2011, 10:13 AM
I'm new here, and haven't got much experience using php yet. Still I think I can be of assistance since I'm currently struggling to get my own installer script running.

With that said requesting the mySQL version requires you to connect to the database. There is no other way around it.

Think of it this way. You want to get 100 from your bank account to get yourself some fancy computer hardware, but you got no proper legitimation to prove who you say you are. Without these credentials you cannot request anything from your account, it doesn't matter if you got the full account ID.

So the only valid way around the problem is:

1. Display a form to receive the database credentials.
2. Connect to the database with the credentials.
3. Display the current version of mySQL on the server.

Now think about it this way. Your end-user has some very imporant data stored inside his database that he doesn't want anyone to get hold of. It can be client's email adresses and then some. These database credentials are there to prevent unauthorized usage of your database. Same goes with the bank to prevent unauthorized usage of your money. Same goes with the keys to your flat. They're there to prevent any thieves from stealing your commodities.

No identification / credentials = access denied.

Here is a script to check the version of mysql from my script:

// Checking the version.
$qry = "SELECT VERSION()";
$result = @mysql_query($qry);
if (!$result) {
die("<font color='red'>Query error: " . mysql_error() . "</font>");
$ver = @mysql_result($result, 0);
print "<font color='green'>MySQL version: <b>$ver</b></font>";

Below is the file conf.php

// conf.php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="1234"; // Mysql password
$db_name="database"; // Database name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

07-26-2011, 05:20 PM
I moved this post here since it doesn't need to resurrect the thread it was posted it, but it may still be useful to someone.

07-27-2011, 06:53 AM
Sorry if I necro-posted. I'm quite good at that skill. With 10% sight on one eye I'm having a hard time locating the post date in most forums.

Anyways I'm glad you find this code useful enough to keep.