Results 1 to 2 of 2

Thread: Sql help

  1. #1
    Join Date
    Sep 2009
    Posts
    1

    Unanswered: Sql help

    Hello,

    I have a script thats already done however I'm just missing sql file that need to be imported into the database in either for the script to run. How to creat a sql using this:
    Code:
    if (!defined('STARTED'))
        die('No direct access.');
    
    /**
     * Connects to database.
     */
    function tinyConnect($host, $userName, $passWord, $dataBase)
    {
        if (($con = mysql_connect($host, $userName, $passWord)) === false) {
            trigger_error('Failed to connect to database. Error: ' . mysql_error(), E_USER_ERROR);
            return false;
        }
        
        if (!mysql_select_db($dataBase, $con)) {
            trigger_error('Failed to select database. Error: ' . mysql_error($con), E_USER_ERROR);
            return false;
        }
        
        return $con;
    }
    
    /**
     * Disconects.
     */
    function tinyDisconnect(&$db)
    {
        if (mysql_close($db))
            unset($db);
        else 
            trigger_error('MySQL error: ' . mysql_error(), E_USER_WARNING);
    }
    
    /**
     * Do query.
     */
    function tinyQuery($query)
    {
        global $db;
        
        if (!($rez = mysql_query($query, $db))) {
            trigger_error('SQL Query error: ' . mysql_error(), E_USER_WARNING);
            return false;   
        }
        
        return $rez;
    }
    
    /**
     * Insert data to table.
     */
    function tinyInsert($table, $fields)
    {
        global $db;
        
        if (!is_array($fields)) {
            return false;
        }
        
        $sql = 'INSERT INTO `' . tinyEscape($table) . '` (';
        $tmp = 'VALUES (';
        
        foreach ($fields as $field => $value) {
            $sql .= '`' . tinyEscape($field) . '`, ';
            $tmp .= "'" . tinyEscape($value) . "', ";
        }
        $sql = substr($sql, 0, -2) . ') ' . substr($tmp, 0, -2) . ')';
        
        if (!mysql_query($sql, $db)) {
            trigger_error('SQL Query error: ' . mysql_error(), E_USER_WARNING);
            return false;   
        }
    Thank you all

  2. #2
    Join Date
    Sep 2009
    Posts
    64
    I think your script was not pasted completely. From the snippet that you pasted, it looks like it's basically just do

    Code:
    INSERT INTO <some_table> VALUES
    (a, b, c),
    (d, e, f)
    <etc>
    ;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •