suche nach in der

mysqli_disable_rpl_parse> <mysqli_client_encoding
Last updated: Fri, 18 May 2012

view this page in

mysqli_connect

(PHP 5)

mysqli_connectAlias von mysqli::__construct()

Beschreibung

Diese Funktion ist ein Alias für: mysqli::__construct()



add a note add a note User Contributed Notes
mysqli_connect
nonerr gmail.com
06-Jul-2007 03:29
This helped me:

<?php
$db
= mysqli_connect($host, $login, $pass, $dbName);
$db->set_charset('utf8');
...
?>
Gazzer
18-Feb-2007 08:52
Yes, it's totally odd that php.ini doesn't seem to allow you to global specify the client connection as utf-8. You might try this in the
my.cnf file

[client]
default-character-set=utf8

[mysqld]
default-character-set=utf8

It didn't work for me, but others may have better luck. In the end I had to specify in the php code as noted below.
Niel Archer
31-Jan-2007 08:13
A quick word about the connection encoding for this extension.  It doesn't appear to be documented anywhere that I can find, but this defaults to latin1 encoding for the connection, regardless of PHP's or MySQL's settings.  I run in a completely UTF-8 setup, and spent days trying to discover the cause of corrupted characters from the Db.  If, like me, you need to work with other than latin1, use the set_charset function/method to switch to your encoding of choice.
jcwebb at dicoe dot com
24-Jan-2007 03:08
PHP520, MYSQL5027, WinServer2003r2

i created a database with no tables
i created a user with no privileges (testuser,testpw,localhost)

<?php
$MYhostname
="localhost"; $MYusername="testuser"; $MYpassword="testpw"; $MYdatabase="mysqlitest";
$MYlink=mysqli_connect($MYhostname, $MYusername, $MYpassword, $MYdatabase) or trigger_error(mysqli_connect_error(),E_USER_ERROR);
printf("Host information: %s\n", mysqli_get_host_info($MYlink));
mysqli_close($MYlink);
?>

This gave an Access Denied error.
But it works with mysql_connect()  !!!!!!!!!!!!!

Solution: give the user a GLOBAL SELECT privilege
or create a table and give a SELECT priviledge to the table.

Hope this helps.
richard at hddbroker dot com
05-Jan-2007 08:04
If you want to suppress any error messages displayed when using mysqli as an object, do the following:

<?php
  $db
= @ new mysqli('localhost', 'user', 'pass', 'dbname');

 
// test for errors
 
if (mysqli_connect_errno()) {
    echo
"Database connection error.\n\n";
    exit();
  }
?>
Eamon Straughn
02-Jan-2007 01:01
Many here have said you can't produce a persistent connection, however this is false if you are using objects take below as an example with strict visibility; sorry about no comments just quite busy but hope this helps someone who wants to broaden their perspective;

class A
{
private $link;
public $objects;

//load all child objects with the connection
public function __construct($classes, $db, $host, $user, $pass)
{
$this->link = $this->connect($db, $host, $user, $pass);

$name = __CLASS__;
           
foreach ($classes as $id => $obj)
{
 if(is_subclass_of($obj,$name))
 {
  $this->objects[$obj] = new $obj($this->link);
}
}

private function connect($db, $host, $user, $pass)
{
$link = new mysqli($host,$user,$pass,$db);

if($link->error) return "could not connect to database server, ". $link->error;
else
return $link;
}

public __destruct($void)
{
if($void) $this->link->close();
}

}

class B extends A
{
private $link;

public function __construct($link)
{
$this->link = $link
}

function getUsers()
{

$q = $this->link->prepare("select id,name,location from users");
$q->execute();

$q->bind_result($id,$name,$location);

$q->fetch();

return array($id,$name,$location);
}

}

example of use:
$classes = array('B');
$db = 'mydatabase';
$host = '127.0.0.1';
$user = 'username';
$pass = 'password';

$a = new A($classes, $db, $host, $user, $pass);

extract($a->objects, EXTR_PREFIX_SAME, 'obj');

$b->getUsers();

this example allows you to initiate one instance of every object as long as it is a child with the same connection. this is just a snippet of a much bigger model.
Polarina
16-Aug-2006 03:09
Just so you know, mysqli_connect(); will also throw a warning on an unsuccessfull connect. To avoid such warnings being shown prefix it with an "@" symbol.

<?php
// Example:
@mysqli_connect();
?>

mysqli_disable_rpl_parse> <mysqli_client_encoding
Last updated: Fri, 18 May 2012