Library/PHP

From Athile

Jump to:navigation, search

Contents

PHP.INI and Other Settings

Using .htaccess to override php.ini settings

.htaccess files can be used to override php.ini settings. This is very useful on servers where you may not have permissions to change the base php.ini file. The syntax is as follows:

php_flag variable.name "value goes here"

Examples:

php_value session.save_path "/home/username/tmp"


Finding Short Tags with grep


MySQL

Creating a new table

 <?php 
 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
 mysql_select_db("Database_Name") or die(mysql_error()); 
 mysql_query("CREATE TABLE tablename ( name VARCHAR(30), 
 age INT, car VARCHAR(30))");
 
 Print "Your table has been created"; 
 ?>

Fetch all rows WHERE

 <?php 
 // Connects to your Database 
 mysql_connect("your.hostaddress.com", "username", "password") or die(mysql_error()); 
 mysql_select_db("Database_Name") or die(mysql_error()); 
 $data = mysql_query("SELECT * FROM friends WHERE pet='Cat'") 
 or die(mysql_error()); 
 Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['name'] . "</td> "; 
 Print "<th>Color:</th> <td>".$info['fav_color'] . "</td> "; 
 Print "<th>Food:</th> <td>".$info['fav_food'] . "</td> "; 
 Print "<th>Pet:</th> <td>".$info['pet'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?>


Navigation
Toolbox