Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

in php how to create cache in core php.please give me proper detail along with all the steps. 2-how do use multidatabase in php.

user-image
Question added by Diwakar Upadhyay Manu , Sr Software Engineer , Suntec Web services
Date Posted: 2013/06/04
Moath Samman
by Moath Samman , Solutions Architect , Hewlett Packard Enterprise (HPE)

Why not trying php Framework that can provide you with these functionality in easy-to-use way? There is pretty much good Frameworks that you can learn in no time.

I'm using CodeIgniter and you can configure it to do the caching job for you along with connecting to multiple databases at a time selecting from a set of Database engines including MySQL, SQLite and Oracle.

Hazem Maattoq
by Hazem Maattoq , Operation Manager , Linkup

<?php

//Create cach // start the output buffer ob_start();

//Your usual PHP script and HTML here ...

$cachefile = "cache/l";

// open the cache file "cache/l" for writing $fp = fopen($cachefile, 'w');

// save the contents of output buffer to the file fwrite($fp, ob_get_contents());

// close the file fclose($fp); // Send the output to the browser ob_end_flush();

// Using several Databases // there are more than one way

//1- First way mysql_query("INSERT INTO kup_emp SELECT * FROM ");

//2- Second way $conn1 = mysql_connect("localhost","root","passw0rd") or die(mysql_error()); $conn2 = mysql_connect("localhost","root","passw0rd") or die(mysql_error()); mysql_select_db("asteriskcdrdb",$conn1); mysql_select_db("pj8v2",$conn2); $query = "SELECT * FROM cdr"; $result = mysql_query($query,$conn1); var_dump($result); $query2 = "SELECT * FROM tb_did_avalaible"; $result2 = mysql_query($query2,$conn2); var_dump($result2);

?>

azhar menshawy
by azhar menshawy , Web developer , Hr elements

Hello,

About question2 You can create any number of databases you want in your project,But when you use any table in your php must select the name of the database that this tabe in it .

for example i want to make backup of some tables from one database to another database(with that tables in it).

i have created two different connection, but the table is not updated.

//this the first database and it's connection

$dbcon1 = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD) or die(mysql_error());

$dbase1 = mysql_select_db(dbname1,$dbcon1) or die(mysql_error());

//this the second database and it's connection

$dbcon2 = mysql_connect(DB_SERVER,DB_USER,DB_PASSWORD,true) or die(mysql_error()); $dbase2 = mysql_select_db(dbname2,$dbcon2) or die(mysql_error()); $query1=mysql_query("SELECT * FROM "); mysql_close($dbcon1); while($row = mysql_fetch_array($query1, MYSQL_NUM)) { mysql_query("INSERT INTO kup_emp VALUES(null,'$row[1]',$row[2])"); mysql_close($dbcon2);

}

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.