Archive: table

 

Posts Tagged ‘table’


If your osCommerce checkout starts behaving badly and bits of info seem to go missing eg billing address then you should definitely try this fix before you tear your hair out completely.
Most osCommerce installs store session information to a MySQL table called (suprisingly) sessions.
Sometimes (I have only seen this twice on umpteen osCommerce sites) the [...]



 

This little PHP function will allow you to import a csv or tab etc delimited text file into a database table. Handy if you need it
PLAIN TEXT
PHP:

function build_table_from_file($tablename, $filepath, $delim="\t") {

    db_query("DROP TABLE IF EXISTS $tablename");

    $fp=fopen($filepath, 'r');

    $headers=false;

    while($r=(($delim=='csv')?fgetcsv($fp):fgets($fp))) {

        if($delim!='csv'){

          [...]



 

If you are feeling lazy, or would like to build in some future proofness into your system, you can use the MySQL Desc query to get table column information and then use this information to create dynamic SQL insertion strings.
For example:
PLAIN TEXT
PHP:

$cols_query = db_query("desc table");

while($cq = mysql_fetch_assoc($cols_query)){

    $cols[]=$cq;

}

foreach($cols as $c){

    if(!empty($_POST[$c['Field']])){

      [...]



 

Sometime you need a PHP script to check for the existence of a MySQL table. This function achieves that for you.
PLAIN TEXT
PHP:

function db_table_exists($table){

    $exists = false;

    $tables_query = db_query("SHOW TABLES FROM " . MYSQL_DB);

    while($t = mysql_fetch_assoc($tables_query)){

        foreach($t as $k=>$v){

            if($v == $table){

    [...]