Results 1 to 9 of 9

Thread: PHP MySQL

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User zombie13's Avatar
    Join Date: Oct:2012
    Location: Bulgaria - Ruse
    Posts: 63

    PHP MySQL


    HTML Code:
    <form method="post" action="process.php">
    <input type="text" name="firstname" /><br>
    <input type="submit" name="submit" value="Submit" />
    process.php
    PHP Code:
    $first_name $_POST['firstname'];
    $dbc mysql_connect('localhost','root','','ninja') or die("Error 1");
    $q "INSERT INTO ivan (first_name) VALUES('$first_name')";
    mysql_query($q) or die("Error 2"); 
    Error 2
    INSERT INTO ivan (first_name) VALUES('Peter Jackson'); .
    php ?

  2. #2
    Joyman's Avatar
    Join Date: Jun:2005
    Location:
    Posts: 1,624
    mysql_select_db("database_name");
    ! Trabajo - NO!

  3. #3
    Registered User zombie13's Avatar
    Join Date: Oct:2012
    Location: Bulgaria - Ruse
    Posts: 63
    .
    Joyman!!!

  4. #4
    ! vbTheKing's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 4,138
    Google.
    PHP Code:
    ...
    ... or die(
    'Error 2:  ' mysql_error()); 
    , mysql_connect . 'ninja', , , , true false .

    $dbc = mysql_connect('localhost','root','','ninja') or die("Error 1");
    ''? * *
    - !
    ...

  5. #5
    The Conquerer I Be RazorJack's Avatar
    Join Date: Jul:2001
    Location:
    Posts: 3,108


    Code:
    class DB {
    	private static $singleton;
    	private $dbObject;
    
    	protected function __construct() {
    		$this->dbObject = new mysqli($MYSQL_IP, 'user', 'pass');
    	}
     
    	public static function instance() {
    		if(!(self::$singleton instanceof self)) {
    			self::$singleton = new self();
    			self::query("SET NAMES 'utf8'");
    			self::get()->set_charset('utf8');
    		}
    		return self::$singleton;
    	}
    
    	public static function get() {
    		return self::instance()->dbObject;
    	}
      
    	public static function query($qry){
    		$result = self::get()->query($qry);
    		if($result){
    			$data = array();
    			if (!is_object($result)) return $data;
    			if ($result->num_rows > 0) {
    				while ($row = $result->fetch_assoc()){
    					$data[] = $row;
    				}
    			}
    			$result->close();
    			return $data;
    		} else return false;
    	}
    	
    	public static function escape($str) {
    		return self::get()->real_escape_string($str);
    	}
    }

  6. #6
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    , ...

    , singleton ?
    , self(), - static().
    , ... .

    , ..

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |