Image functions  
 
  String functions  
 
  Math functions  
 
  home  
 
  ask us  
 

 
php
Programming


php Applications
MySQL Database
php-MySQL
cakePHP & Joomla
PL-SQL & PHP
Related projects


© The scientific sentence. 2010

Connection



<?php
//start a session
session_start();
// db properties:
$dbhost = 'localhost';
$dbuser = 'root'; 
$dbpass = 'pass_word';    
$dbname = 'academia';
?>

2. Check the connection

<?php
//in the case of failure to connect to the database:
$conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("Could not 
connect to the database: " . mysql_error());

//in the case of failure toselect a  database:
mysql_select_db ($dbname) or die ("I cannot select the 
database '$dbname' because: " . mysql_error());
?>

3. Close the connection

<?php
mysql_close($conn);
?>


4. Creating a library

Set the above code as config.php file in 
the library directory: library/config.php 
This file will be called when needed.

library/config.php
<?php //start a session session_start(); // db properties: $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'pass_word'; $dbname = 'academia'; ?> //in the case of failure to connect to the database: $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("Could not connect to the database: " . mysql_error()); //in the case of failure toselect a database: mysql_select_db ($dbname) or die ("I cannot select the database '$dbname' because: " . mysql_error());


  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
Perl
|
php
|
green cat
|
contact
|


© Scientificsentence 2010. All rights reserved.