Skip to main content

Posts

Showing posts from June, 2012

Compare 2 mysql databases

Below code will list all the tables with fields (& type) and total records in each table, so that we can verify whether fields are same in both database fields and record counts. <?php mysql_connect("localhost", "user1", "pwd1") or die(mysql_error()); mysql_select_db("db1") or die(mysql_error()); $tables = array('tbl1', 'tbl2','tbl3'); echo "<table  border='1' style='float: left'>"; foreach($tables as $tbl){   $sel = "SELECT COUNT(1) FROM $tbl";   $res = mysql_query($sel);   $rec = mysql_fetch_row($res);     echo "<tr><th colspan='2'>$tbl ($rec[0])</th></tr>";   $sel1 = "SHOW FIELDS FROM $tbl";   $res1 = mysql_query($sel1) or die($sel1.mysql_error());   while($rec1 = mysql_fetch_row($res1)){     echo "<tr><td>$rec1[0]</td><td>$rec1[1]</td></tr>";   } } ech...

HTTP POST without cURL using PHP

I don't think we do a very good job of evangelizing some of the nice things that the PHP streams layer does in the PHP manual, or even in general. At least, every time I search for the code snippet that allows you to do an HTTP POST request, I don't find it in the manual and resort to reading the source. (You can find it if you search for "HTTP wrapper" in the online documentation, but that's not really what you think you're searching for when you're looking).  So, here's an example of how to send a POST request with straight up PHP, no cURL: <?php      function do_post_request($url, $data, $optional_headers = null) {           $params = array('http' => array(                                 'method' => 'POST',                   ...

SQL JOINS

Practice and crack the interviews on JOINS.