PHPmyadmin umlaut is going to be '?' - php

Im trying to write into my database through android (PHP script).Now... When I want to write a sentence like "Ich bin Müde" (German) it saves it like "Ich bin M?de". I already tried to change the collation of my column from latin1_general_ci to latin1_german1_ci but then I don't get any inputs. So the script is not saving my data into my tables. Is there a easy for a solution? Thanks to everyone
Php script
<?php
$hostname = "host";
$username = "admin";
$password = "pass";
$localhost = mysql_connect($hostname,$username,$password)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db("db");
$sql = mysql_query("INSERT INTO tbas VALUES(23,NULL,22,'Ich bin Müde','Ich bin Müde 2'));";
...
?>

Related

How do you fetch from a mysql database?

I'm relatively new to any type of programming or coding. I'm not quite understanding why no matter what adjustments I make to my php file I can't seem to pull any data from a table.
Here is a link to the table: https://i.gyazo.com/4ad5e860895014c49dbe0539c38cdec2.png
Above is the test table I have been trying to use. From what I can understand I'm connecting to the database okay, but all of my problems come after the connection. Also, I'm using php 7.0 so a lot of the information I'm finding online has not been helpful.
If there is something glaringly wrong with my table or in my code, please let me know.
Here is my code:
'''
//Set Variables
$serverName = "localhost";
$userName = "root";
$password = "";
$databaseName = "test";
//Create Connection
$connection = mysqli_connect($serverName,$userName,$password,$databaseName);
//Check Connection
if(!$connection){
die("Connection failed: ".mysqli_connect_error());
}
echo "Connected successfully <br>";
//Fetch Data
$query = "SELECT * from table1";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result, MYSQLI_NUM);
printf ($row[1], $row[2]);
mysqli_free_result($result);
mysqli_close($connection);
I figured out the issue a few hours ago. The code I had posted would have worked perfectly fine if I was connecting to the port for MySQL rather than MariaDB. Didn't realize that the port that MariaDB was connected to was the default.
MariaDB by default was port 3306, but MySQL was 3308. After specifying 'localhost:3308' I was able to start properly pulling rows from my tables.

Select hebrew from mysql database

honestly I am coming here after trying everything I could find online in order to fix that problem but nothing worked..
I have a phpmyadmin database table that encoded to utf_general_ci, when I insert data in Hebrew into it it works fine and I can see the Hebrew in the table on PhpMyAdmin, but when I need to retrieve the Hebrew data from the table that's when the problem starts...
right now I am using a simple sql query to select data from the table and I tried every code that should fix it I could find online but nothing seems to work.
my current code is:
<?php
$db = "android";
$username = "root";
$password = "";
$host = "localhost";
$sql = "select * from sample;";
$conn = mysqli_connect($host,$username,$password,$db);
$conn->set_charset('utf8');
$result = mysqli_query($conn,$sql);
$response = array();
while($row = mysqli_fetch_array($result))
{
array_push($response,array($row[0],$row[1]));
}
$str = json_encode(array($response));
echo $str;
mysqli_close($conn);
?>
and the output of the Hebrew word is \u05d4\u05d9\u05d9 what seems like a different encoding, my php file is encoded to UTF-8 and I am using npp to write it.
please try helping me out on this one cause I couldn't find an answer
This is a json_encode() behaviour, by default Unicode char are escaped as \u...
Try with JSON_UNESCAPED_UNICODE flag :
<?php
echo json_encode($arr, JSON_UNESCAPED_UNICODE);

Remote connect to database at demo.phpmyadmin.net?

I teach a little php and SQL and I would like my students to temporarily connect to a database they have testet on demo.phpmyadmin.net, is this done simply by using:
$username = "root";
$password = "";
$hostname = "192.168.30.23";
If so it doesn't seem to work for me. :)

when changing database local to online page blank

I've recently made a new database that I had local. Everything worked fine and the scripts I've used (mysql and php codes) have been working properly. Since I've changed the database from local to online it has only caused problems with my script. Of course I've changed the details of connecting to MySQL database (having a password and such). Also, the content after the script won't work either.
Note: I haven't changed my script AT ALL. I've only changed the connection part.
$dbhost = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "compunll_itnj01";
$con = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$so = $con->prepare("SELECT * FROM besteloverzicht");
$so->execute();
--- rest of code
My apologies if I've forgotten to put anything further here. You can ask me and I'll respond asap!
Try to set the ip address of your db online
$dbhost = 'xx.xxx.xxx.xxx';

mysql_insert_id() suddenly stopped working

Don't know how to say this, but I have used mysql_insert_id() for many many years. Recently I included it in my web applications and worked well, I have successfully received 50 transactions and was happy.
All of a sudden all my transactions are coming in with ids equal 0, I Google'd around and read something about persistent connection being set to true? I just want me to make sure I give the right info to my network server guy, God knows, whenever something changes, they don't let me know, I only find out when my code all of a sudden breaks.
is there another function to use other than mysql_insert_id() in my PHP/MySQL code?
just for those who want to see code here is what i have: I am not including "id" as it is "auto increment not null primary key, etc"
<?php
$db_host2 = 'localhost';
$db_user2 = 'different';
$db_pass2 = 'different';
$db_name2 = 'different';
$conn2 = &NewADOConnection('mysqlt');
$db2 = $conn2->Connect($db_host2,$db_user2,$db_pass2,$db_name2);
if($conn2->isConnected()==false)
die("Could not connect to the database. Please try again in the next few minutes.");
$db_host = 'localhost';
$db_user = 'admin';
$db_pass = 'pass';
$db_name = 'name';
include_once('adodb/adodb.inc.php');
define('ADODB_FETCH_ASSOC',2);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$conn = NewADOConnection('mysqlt');
$db = $conn->Connect($db_host,$db_user,$db_pass,$db_name);
if($conn->isConnected()==false)
die("Could not connect to the database. Please try again in the next few minutes.");
$q="insert into tableA(name,address,phone) values ('','','')"
$rs=$conn->execute($q);
$myid=mysql_insert_id();
?>
You just need 1 configuration example :
// database config
$DB_TYPE = "mysql";
$DB_HOST = "xxxxx";
$DB_USER = "xxxx";
$DB_PWD = "xxxx";
$DB_NAME = "xxx";
then use last insert ID for :
$db->Insert_ID

Categories