Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check MySQL version

    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:
    Code:
    <?
    	// Checking the version.
    	include'conf.php';
    	$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>";
    	ob_end_flush();
    ?>
    Below is the file conf.php
    Code:
    <?php
    	// conf.php
    	ob_start();
    	$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");
    ?>
    Last edited by jobromedia; 07-26-2011 at 09:23 AM. Reason: Added some scripts.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •